/**
 * SSC玩法
 * Lion @2018.01.31
 */
$(function () {

    //加减插件
    alignmentFns.initialize();
    //tab玩法切换点击的时候的通用操作
    $('.buyNumber').on("click","a",function(){
        var obj = $(this);
        if(obj.hasClass('curr'))
        {
            obj.removeClass('curr');
            var type = obj.parents('.sscCheckNumber').data('type');
            oneCountNote(type);
        }else
        {
            obj.addClass('curr');
            var type = obj.parents('.sscCheckNumber').data('type');
            oneCountNote(type);
        }
    });

    //通用侧边栏选择
    $('.buyNumberFilter a').click(function (){
        var type = $(this).data('id');
        //查找到自己父级的div
        var obj = $(this).parents('.selectNormal').find('.buyNumber');
        var types = obj.parents('.sscCheckNumber').data('type');
        obj.find('a').removeClass('curr');
        switch (type)
        {
            case 1:
                obj.find('a').addClass('curr');

                break;
            case 2:
                obj.find('a:gt(4)').addClass('curr');
                break;
            case 3:
                obj.find('a:lt(5)').addClass('curr');
                break;
            case 4:
                obj.find('a:odd').addClass('curr');
                break;
            case 5:
                obj.find('a:even').addClass('curr');
                break;
            case 6:
                obj.removeClass('curr');
                break;
        }
        oneCountNote(types);
    });
});

//通用选择
function betting()
{
    //tab玩法切换点击的时候的通用操作
    $('.buyNumber').on("click","a",function(){
        var obj = $(this);
        if(obj.hasClass('curr'))
        {
            obj.removeClass('curr');

            var type = obj.parents('.sscCheckNumber').data('type');
            oneCountNote(type);
            return;
        }else
        {
            obj.addClass('curr');
            var type = obj.parents('.sscCheckNumber').data('type');
            oneCountNote(type,obj);
            return;
        }
    });


    //通用侧边栏选择
    $('.buyNumberFilter a').click(function (){
        var type = $(this).data('id');
        //查找到自己父级的div
        var obj = $(this).parents('.selectNormal').find('.buyNumber');
        var types = obj.parents('.sscCheckNumber').data('type');
        obj.find('a').removeClass('curr');
        switch (type)
        {
            case 1:
                obj.find('a').addClass('curr');
                oneCountNote(types);
                break;
            case 2:
                obj.find('a:gt(4)').addClass('curr');
                oneCountNote(types);
                break;
            case 3:
                obj.find('a:lt(5)').addClass('curr');
                oneCountNote(types);
                break;
            case 4:
                obj.find('a:odd').addClass('curr');
                oneCountNote(types);
                break;
            case 5:
                obj.find('a:even').addClass('curr');
                oneCountNote(types);
                break;
            case 6:
                obj.removeClass('curr');
                oneCountNote(types);
                break;
        }
    });
}

$('.Panel .betBtn').click(function(){
    var type = $(this).parents('.Panel').prev().find('div:first').data('type');
    var wf = $(this).parents('.Panel').prev().find('div:first').data('wf');
    create(type,wf);
});

/**
 * 通用加入到底部框内
 * type为玩法类型
 */

 function create(type,wf)
 {
    var zhu = $('.betTotal').find('em:first-child').html();
    var money = $('.betTotal').find('.tag_show_bet_amount').html();
    console.log(money);
    switch (type) {
        case 'one':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){  
                basic += $(this).html() + " "; 
            });
  
            var html = '<tr><td><i class="order_type">['+wf+'] -,-,0 1 2 3 4 <span>...</span></i> <a class="orderDetail">详细</a></td> <td>'+zhu+'注</td> <td>1倍</td><td>'+money+'元</td> <td>可中金额<i class="orderMoney">19.60<i>元</i></i></td> <td></td><td><i class="orderCancel">删除</i></td></tr>';
            
            $('.checkedList table tbody').append(html);
            console.log(basic);
            console.log(html);
            break;
    
        default:
            alert('网络错误');
            break;
    }
 }
// 减注
$('.tag_bet_operation').on('click', '.tag_betnum_subtract', function (){
	// 如果已经是0注，则不操作
	if($('.tag_betnum').val() == 0) { return; }
	$(this).removeClass('off');
	$('.tag_betnum').val(parseInt($('.tag_betnum').val())-1);
	if($('.tag_betnum').val() == 0) { $(this).addClass('off'); }
	acount();
})
$('.tag_betnum_subtract').click(function(){
    if($('.tag_betnum').val() == 1) { return; }
	$(this).removeClass('off');
	$('.tag_betnum').val(parseInt($('.tag_betnum').val())-1);
    if($('.tag_betnum').val() == 1) { $(this).addClass('off'); }
    acount();
});
// 加注
$('.tag_bet_operation').on('click', '.tag_betnum_add', function (){
	$('.tag_betnum').val(parseInt($('.tag_betnum').val())+1);
	$('.tag_betnum_subtract').removeClass('off');
	acount();
})
$('.tag_betnum_add').click(function(){
    $('.tag_betnum').val(parseInt($('.tag_betnum').val())+1);
    $('.tag_betnum_subtract').removeClass('off');
    acount();
});

/**
 * 计算倍数
 */
function acount()
{

}
//通用计算此次下注的费用
function oneCountNote(type,val)
{
    var zhu = 0;
    var money = 0;
    switch (type)
    {
        case 'one':
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                zhu += 1;
            });

            break;
        case 'two':case 'hr':
            var s1 = 0;
            var s2 = 0;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var way = $(this).parents('.selectNormal').data('type');
                if(way == 'wan')
                {
                    s1 += 1;
                }else{
                    s2 += 1;
                }
            });
            zhu = parseInt(s1) * parseInt(s2);
            break;
        case 'two3':case 'hr3':
            var arr = new Array();
            var k = 0;
            var line = 9;
            for(i=0;i<19;i++)
            {
                if(i <= line)
                {
                    k++;
                    arr[i] = k;
                }else{
                    k--;
                    arr[i] = k;
                }
            }
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var num = parseInt($(this).text());
                zhu += parseInt(arr[num]);
            });
            break;
        case 'two4':case 'hr4':
            var arr = new Array();
            arr[0] = 10;arr[1] = 18;arr[2] = 16;arr[3] = 14;arr[4] = 12;
            arr[5] = 10;arr[6] = 8;arr[7] = 6;arr[8] = 4;arr[9] = 2;

            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var num = parseInt($(this).text());
                zhu += parseInt(arr[num]);
            });
            break;
        case 'two5':case 'hr5':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct2,{str:basic,num:2},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'two7':case 'hr7':
            var arr = new Array();
            arr[1] = 1;arr[2] = 1;arr[3] = 2;arr[4] = 2;arr[5] = 3;arr[6] = 3;arr[7] = 4;arr[8] = 4;arr[9] = 5;arr[10] = 4;arr[11] = 4;
            arr[12] = 3;arr[13] = 3;arr[14] = 2;arr[15] = 2;arr[16] = 1;arr[17] = 1;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var num = parseInt($(this).text());
                zhu += arr[num];
            });
            break;
        case 'two8':case 'hr8':
            var s = val.html();
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(){
                if($(this).html() != s)
                {
                    $(this).removeClass('curr');
                }
            });
            zhu = 9;
            break;
        case 'q3':case 'z3':case 'h3':
            var s1 = 0;
            var s2 = 0;
            var s3 = 0;
            var s4 = 0;
            var s5 = 0;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var way = $(this).parents('.selectNormal').data('type');
                if(way == 'wan')
                {
                    s1 += 1;
                }else if(way == 'qian'){
                    s2 += 1;
                }else if(way == 'bai'){
                    s3 += 1;
                }else if(way == 'shi'){
                    s4 += 1;
                }else if(way == 'ge'){
                    s5 += 1;
                }
            });
            if(type == 'q3')
            {
                zhu = parseInt(s1) * parseInt(s2) * parseInt(s3);
            }else if(type == 'z3')
            {
                zhu = parseInt(s2) * parseInt(s3) * parseInt(s4);
            }else if(type == 'h3')
            {
                zhu = parseInt(s3) * parseInt(s4) * parseInt(s5);
            }

            break;
        case 'q33':case 'z33':case 'h33':
            var arr = new Array();
            arr[0] = 1;arr[1] = 3;arr[2] = 6;arr[3] = 10;arr[4] = 15;arr[5] = 21;arr[6] = 28;arr[7] = 36;arr[8] = 45;arr[9] = 55;arr[10] = 63;arr[11] = 69;arr[12] = 73;arr[13] = 75;arr[14] = 75;arr[15] = 73;arr[16] = 69;arr[17] = 63;arr[18] = 55;arr[19] = 45;arr[20] = 36;arr[21] = 28;arr[22] = 21;arr[23] = 15;arr[24] = 10;arr[25] = 6;arr[26] = 3;arr[27] = 1;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var num = parseInt($(this).text());
                zhu += arr[num];
            });
            break;
        case 'q34':case 'z34':case 'h34':
            var arr = new Array();
            arr[0] = 10;arr[1] = 54;arr[2] = 96;arr[3] = 126;arr[4] = 144;arr[5] = 150;arr[6] = 144;arr[7] = 126;arr[8] = 96;arr[9] = 54;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var num = parseInt($(this).text());
                zhu += arr[num];
            });
            break;
        case 'q35':case 'z35':case 'h35':
            var arr = new Array();
            arr[1] = 1;arr[2] = 2;arr[3] = 2;arr[4] = 4;arr[5] = 5;arr[6] = 6;arr[7] = 8;arr[8] = 10;arr[9] = 11;arr[10] = 13;arr[11] = 14;arr[11] = 14;arr[12] = 14;arr[13] = 15;arr[14] = 15;arr[15] = 14;arr[16] = 14;arr[17] = 13;arr[18] = 11;arr[19] = 10;arr[20] = 8;arr[21] = 6;arr[22] = 5;arr[23] = 4;arr[24] = 2;arr[25] = 2;arr[26] = 1;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var num = parseInt($(this).text());
                zhu += arr[num];
            });
            break;
        case 'q36':case 'z36':case 'h36':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct2,{str:basic,num:2},function(data){
                zhu += (parseInt(data) * 2);
            });
            break;
        case 'q37':case 'z37':case 'h37':case 'wx11':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct3,{str:basic,num:3},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'q39':case 'z39':case 'h39':
            var s = val.html();
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(){
                if($(this).html() != s)
                {
                    $(this).removeClass('curr');
                }
            });
            zhu = 54;
            break;
        case 'q312':case 'z312':case 'h312':
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                zhu += 1;
            });
            break;
        case 'q313':case 'z313':case 'h313':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct2,{str:basic,num:2},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'sx':case 'wx':
            var s1 = 0;
            var s2 = 0;
            var s3 = 0;
            var s4 = 0;
            var s5 = 0;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var way = $(this).parents('.selectNormal').data('type');
                if(way == 'wan'){
                    s1 += 1;
                }else if(way == 'qian'){
                    s2 += 1;
                }else if(way == 'bai'){
                    s3 += 1;
                }else if(way == 'shi'){
                    s4 += 1;
                }else if(way == 'ge'){
                    s5 += 1;
                }
            });
            zhu = parseInt(s2) * parseInt(s3) * parseInt(s4) * parseInt(s5);
            break;
        case 'sx3':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct4,{str:basic,num:4},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'sx4':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct5,{str:basic,num:5},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'sx5':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct2,{str:basic,num:2},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'sx7':case 'wx9':
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                zhu += 1;
            });
            break;
        case 'sx8':case 'wx10':
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct2,{str:basic,num:2},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'wx3':
            var basic = "";
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                basic += $(this).html() + ",";
            });
            basic = basic.substring(0, basic.lastIndexOf(','));

            $.ajaxSetup({
                async : false
            });
            $.post(ct5,{str:basic,num:5},function(data){
                zhu += parseInt(data);
            });
            break;
        case 'wx12':case 'wx13':case 'wx14':case 'wx15':
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                zhu += 1;
            });
            break;
        case 'dx':case 'dx1':
            var s1 = 0;
            var s2 = 0;
            var s3 = 0;
            var s4 = 0;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){
                var way = $(this).parents('.selectDsds').data('type');
                if(way == 'wan'){
                    s1 += 1;
                }else if(way == 'qian'){
                    s2 += 1;
                }else if(way == 'shi'){
                    s3 += 1;
                }else if(way == 'ge'){
                    s4 += 1;
                }
            });
            if(type == 'dx')
            {
                zhu = parseInt(s1) * parseInt(s2);
            }else
            {
                zhu = parseInt(s3) * parseInt(s4);
            }

            break;
        case 'dx2':case 'dx3':
            var s1 = 0;
            var s2 = 0;
            var s3 = 0;
            $('.sscCheckNumber[data-type='+type+']').find('.buyNumber a.curr').each(function(i,k){

                var way = $(this).parents('.selectDsds').data('type');
                if(way == 'wan'){
                    s1 += 1;
                }else if(way == 'qian'){
                    s2 += 1;
                }else if(way == 'bai'){
                    s3 += 1;
                }
            });
            zhu = parseInt(s1) * parseInt(s2) * parseInt(s3);
            break;
    }
    money = zhu * 2+'.00';
    $('.betTotal').find('em:first-child').html(zhu);
    $('.betTotal').find('.tag_show_bet_amount').html(money);

    //提交订单

}